package com.ccl.iot.ir;


import android.util.Log;

import com.ccl.iot.publics.Messager;
import com.hzy.tvmao.KookongSDK;
import com.hzy.tvmao.interf.IRequestResult;
import com.kookong.app.data.BrandList;
import com.kookong.app.data.RemoteList;
import com.kookong.app.data.SpList;
import com.kookong.app.data.StbList;

import java.util.Arrays;
import java.util.List;

public class KKSDKUtils {
    /*
    * public int STB = 1; //机顶盒
    * public int TV  = 2; //电视
    * public int BOX = 3; //网络盒子
    * public int DVD = 4; //DVD
    * public int AC  = 5; //空调
    * public int PRO = 6; //投影仪
    * public int PA  = 7; //功放
    * public int FAN = 8; //风扇
    * public int SLR = 9; //单反相机
    * public int Light = 10; //开关灯泡
    * public int AIR_CLEANER = 11;// 空气净化器
    * public int WATER_HEATER = 12;// 热水器
    */

    public void getOperaters(String province, String city, String county) {
        //获取指定城市的AreaId
        KookongSDK.getAreaId(province, city, county, new IRequestResult<Integer>() {

            @Override
            public void onSuccess(String msg, Integer result) {
                //获取指定AreaId下的运营商列表
                KookongSDK.getOperaters(result, new IRequestResult<SpList>() {

                    @Override
                    public void onSuccess(String msg, SpList result) {
                        List<SpList.Sp> sps = result.spList;
                        for (int i = 0; i < sps.size(); i++) {
                            Log.e("getIPTV", "The Stb is " + sps.get(i).spName);
                            Log.e("getIPTV", "The Stb is " + sps.get(i).type);
                        }
                    }

                    @Override
                    public void onFail(Integer errorCode, String msg) {
                        Messager.Show("获取运营商列表错误");
                        Log.e("getOperaters", "msg: " + msg + ", errorCode: " + errorCode);

                    }
                });
            }

            @Override
            public void onFail(Integer errorCode, String msg) {
                Messager.Show("获取AreaId错误");
                Log.e("getAreaId", "msg: " + msg + ", errorCode: " + errorCode);
            }
        });
    }

    public void getIPTV(int spid) {
        //根据spid 获取IPTV列表
        KookongSDK.getIPTV(spid, new IRequestResult<StbList>() {

            @Override
            public void onSuccess(String msg, StbList result) {
                List<StbList.Stb> stbs = result.stbList;
                for (int i = 0; i < stbs.size(); i++) {
                    Log.e("getIPTV", "The Stb is " + stbs.get(i).bname);
                }

            }

            @Override
            public void onFail(Integer errorCode, String msg) {
                Messager.Show("获取IPTV列表错误");
                Log.e("getIPTV", "msg: " + msg + ", errorCode: " + errorCode);
            }
        });
    }

    public void getBrandListFromNet(int devType) {
        // 获取电视机, 空调等, (除STB以外) 的设备品牌列表
        KookongSDK.getBrandListFromNet(devType, new IRequestResult<BrandList>() {

            @Override
            public void onSuccess(String msg, BrandList result) {
                List<BrandList.Brand> stbs = result.brandList;
                for (int i = 0; i < stbs.size(); i++) {
                    Log.e("getBrandListFromNet", "The Brand is " + stbs.get(i).cname + ", id: " + stbs.get(i).brandId);
                }
            }

            @Override
            public void onFail(Integer errorCode, String msg) {
                Messager.Show("获取设备品牌列表错误");
                Log.e("getBrandListFromNet", "msg: " + msg + ", errorCode: " + errorCode);
            }
        });
    }

    public void getAllRemoteIds(int type, int brandId, int spId, int areaId) {
        //获取指定运营商, 指定AreaId下的遥控器id brandid传0
        KookongSDK.getAllRemoteIds(type, brandId, spId, areaId, new IRequestResult<RemoteList>() {

            @Override
            public void onSuccess(String msg, RemoteList result) {
                List<Integer> remoteids = result.rids;
                String res = Arrays.toString(remoteids.toArray());
                Log.e("getAllRemoteIds", "remoteids: " + res);
            }

            @Override
            public void onFail(Integer errorCode, String msg) {
                Messager.Show("获取rid错误");
                Log.e("getAllRemoteIds", "msg: " + msg + ", errorCode: " + errorCode);
            }
        });
    }

    public void testIRDataById() {

    }

    public void getIRDataById(){

    }

}
